package com.han.fu.api.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.han.fu.api.business.model.ao.CommentAddAo;
import com.han.fu.api.business.model.ao.CommentDeleteAo;
import com.han.fu.api.business.model.ao.CommentPageAo;
import com.han.fu.api.business.model.vo.CommentInfoVo;
import com.han.fu.api.business.model.vo.CommentVo;
import com.han.fu.api.business.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 评论接口
 *
 * @author: star
 * @date: 2021-08-05
 */
@RestController
public class CommentController {

    @Autowired
    ICommentService iCommentService;

    /**
     * 评论分页查询
     *
     * @param ao 分页查询条件
     * @return Page<CommentVo> 分页数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/comment/page")
    public Page<CommentVo> queryCommentPage(@Validated @RequestBody CommentPageAo ao) {
        return iCommentService.queryCommentPage(ao);
    }

    /**
     * 评论明细查询
     *
     * @param id 主键
     * @return CommentInfoVo 明细
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @GetMapping("/comment/detail")
    public CommentInfoVo queryCommentDetail(@NotNull(message = "ID不能为空") @RequestParam String id) {
        return iCommentService.queryCommentDetail(id);
    }

    /**
     * 评论新增数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/comment/add")
    public void addComment(@Validated @RequestBody CommentAddAo ao) {
        iCommentService.addComment(ao);
    }

    /**
     * 评论删除数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/comment/delete")
    public void deleteComment(@Validated @RequestBody CommentDeleteAo ao) {
        iCommentService.deleteComment(ao);
    }

}